﻿using IdentityServer4;
using IdentityServer4.Models;
using IdentityServer4.Test;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AuthServer
{

    public class ServiceConstants
    {
        public const string ProductService = "productservice";
    }


    public class IdentityConfiguration
    {

        public static IEnumerable<ApiResource> ApiResource()
        {
            return new[] {
                new ApiResource(ServiceConstants.ProductService,"产品服务")
            };
        }

        public static IEnumerable<Client> Clients()
        {
            return new[] {
                new Client{
                    ClientId = "js.implicit",
                    ClientName = "Js Client (Implicit)",

                    AllowedGrantTypes = GrantTypes.Implicit,
                    
                    RedirectUris = {
                        "http://localhost:5002/oidc/login-callback.html",
                        "http://localhost:5002/oidc/refresh-token.html"
                    },
                    PostLogoutRedirectUris = {
                        "http://localhost:5002/"
                    },
                    AllowedScopes = {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        ServiceConstants.ProductService
                    },

                    AllowedCorsOrigins =
                    {
                        "http://localhost:5001/",
                        "http://localhost:5002/"
                    },

                    AccessTokenLifetime=10,

                    AllowOfflineAccess = true,
                    AllowAccessTokensViaBrowser = true,
                }
            };
        }


        public static IEnumerable<IdentityResource> GetIdentityResources()
        {
            return new List<IdentityResource>
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile()
            };
        }

        public static List<TestUser> Users()
        {
            return new List<TestUser>(){

                new TestUser{
                    SubjectId = "00001",
                    Username = "simongui@qq.com",
                    Password = "888888"
                }
            };
        }



    }
}
